package com.team.appinfo.bgcontroller;

import com.github.pagehelper.PageInfo;
import com.team.appinfo.entity.AppInfo;
import com.team.appinfo.entity.AppVersion;
import com.team.appinfo.service.AppInfoService;
import com.team.appinfo.service.AppVersionService;
import com.team.appinfo.util.AppinfoDicontion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller(value = "AppInfoController2")
public class AppInfoController {

    @Autowired
    private AppInfoService appInfoService;
    @Autowired
    private AppVersionService appVersionService;

    @RequestMapping(value = "/noPassAppInfo")
    public String noPassAppInfo(AppinfoDicontion appinfoDicontion, Model model) {
        PageInfo<AppInfo> pageInfo = appInfoService.getNoPassAppInfo(appinfoDicontion);
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("condition", appinfoDicontion);
        return "backend/applist";
    }


    // //根据appId查询当前数据
    @RequestMapping("/getBgAppInfo")
    public String getBgAppInfo(Long id, Model model) {
        AppInfo appInfo = appInfoService.getModernAppInfo(id);
        AppVersion lastAppVersion = appVersionService.getLastAppVersion(id);
        model.addAttribute("appinfo", appInfo);
        model.addAttribute("appVersion", lastAppVersion);
        return "backend/appcheck";
    }


    //审核状态
    @RequestMapping("/checksave")
    public String checksave(Long id, Long status) {
        int tem = this.appInfoService.approvalStatus(id, status);
        if (tem > 0) {
            return "redirect:noPassAppInfo";
        } else {
            return "redirect:jsp/error.jsp";
        }
    }
}
